package cn.lcsjsxy.yxz.day.Practice.Thread;

public class Practice1 {
        //基础线程创建
    public static void main(String[] args) {

        //创建两个线程，分别打印 1-10 和 11-20 的数字，要求两个线程交替执行（使用 join () 方法）。

        Thread thread1 = new Thread(() -> {
            for (int i = 1; i <= 10; i++) {
                System.out.println("线程1: " + i);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 11; i <= 20; i++) {
                System.out.println("线程2: " + i);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        try {
            thread1.start();
            thread1.join();
            thread2.start();
            thread2.join();
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
